package cn.meizhu.org.controller;

import cn.meizhu.org.domain.Shop;
import cn.meizhu.org.domain.Systail;
import cn.meizhu.org.query.ShopQuery;
import cn.meizhu.org.query.SystailQuery;
import cn.meizhu.org.service.IShopService;
import cn.meizhu.org.service.ISystailService;
import cn.meizhu.util.AjaxResult;
import cn.meizhu.util.PageInfo;
import cn.meizhu.util.QueryResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/systail")
@RestController
@Api(tags = "字典详情维护接口")
//@CrossOrigin
public class SystailController {

    @Autowired
    private ISystailService systailService;


    @PutMapping
    @ApiOperation(value = "字典详情添加或者修改", notes = "有id就是修改，没有id就是新增")
    public AjaxResult addAndUpdDepartment(@RequestBody Systail systail){
        try {
            if (systail.getId() == null){
                systailService.save(systail);
            }else {
                systailService.update(systail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }


    @DeleteMapping("/{id}")
    @ApiOperation(value = "这是字典详情删除")
    public AjaxResult delDepartmentById(@PathVariable("id") Long id){
        try {
            systailService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询字典详情中指定数据")
    public Systail findDepartmentById(@PathVariable("id") Long id){
        return systailService.findById(id);
    }

    @GetMapping
    @ApiOperation(value = "查询字典详情全部数据")
    public List<Systail> findDepartments(){
        return systailService.findAll();
    }


    @PostMapping
    public QueryResult<Systail> queryPage(@RequestBody SystailQuery systailQuery){
        return systailService.queryPage(systailQuery);
    }

//    @PostMapping("/byTypeId/{id}")
//    public PageInfo<Systail> byTypeId(@PathVariable("id") Long id){
//        return systailService.byTypeId(id);
//    }

}
